<?php

include 'C:\\xampp\htdocs\AI-VAS-WEBSITE\trunk\dao_class\User.php';
include 'C:\\xampp\htdocs\AI-VAS-WEBSITE\trunk\dao_class\UserDao.php';
include 'C:\\xampp\htdocs\AI-VAS-WEBSITE\trunk\dao_class\Datasource.php';


$dbHost = "localhost";
$dbName = "ai-vas";
$dbuser = "root";
$dbpasswd = "";

//connect to the database

$connect = new Datasource($dbHost, $dbName, $dbuser, $dbpasswd);
$user = new User();
$userdao = new UserDao();
if (isset($_POST['Registrieren'])) {
    if ((!empty($_POST['nachname'])) || (!empty($_POST['vorname'])) || (!empty($_POST['pseudo'])) || (!empty($_POST['email'])) || (!empty($_POST['pwd'])) || (!empty($_POST['pwd1']))) {
        $user->setName($_POST['nachname']);  
        $user->setVorname($_POST['vorname']); 
        $user->setPseudo($_POST['pseudo']);
        $user->setEmail($_POST['email']);
        $user->setPassword ($_POST['pwd']);
        $password1      = $_POST['pwd1'];
        $user->setGeschlecht("M");
        $user->setHausnummer(39);
        $user->setBild(" ");
        $user->setLevel_admin(2);
        $user->setPostleitzahl(36037);
        $user->setStrasse(123);
        $user->setWohnort("Fulda");

        if ($user->getPassword() == $password1) {
            $sql = "SELECT password FROM user WHERE pseudo='" . $user->getPseudo() . "'";
            $result = $connect->execute($sql);
            $sql1 = "SELECT password FROM user WHERE email='" . $user->getEmail() . "'";
            $result1 = $connect->execute($sql1);
            
            if ($result['pseudo'] != $user->getPseudo()) {
                //echo "<h3 align='center'>Erfolgreiche Aufnahme ! Sie können jetzt sie sich einloggen.</br>"; 
                $userdao->create($connect, $user);
                mysql_close();
                include('login.php');
                exit;
            } else {
                echo "Dieses Pseudo ist schon benutzt!!! Bitte verändern sie ihr pseudo.";
                include('registrieren.php');
                exit;
            }
        } else {
            echo "Unwahres Passwort!!! Bitte versuchen sie nochmal!";
            include('registrieren.php'); 
            exit;
        }
    }
}
?>